<?php
// +----------------------------------------------------------------------
// | 验证器
// +----------------------------------------------------------------------
declare(strict_types=1);

namespace app\validate;

use think\Validate;

/**
 * 用户访问验证器
 *
 * Class AccessUsersValidate
 * @package app\validate
 */
class AccessUsersValidate extends Validate
{
    // 验证规则
    protected $rule =   [
        'uid'          => 'require|number',
        'passport'     => 'require',
        'password'     => 'require',
        'phone'        => 'require|regex:^1[3-9]\d{9}$',
        'code'         => 'require|min:6|max:6',
        'deviceId'     => 'require|max:100',
        'refreshToken' => 'require',
    ];

    // 错误消息
    protected $message  =   [
        'passport.require' => '账号不能为空',
        'password.require' => '密码不能为空',
        'code'             => '无效的验证码',
        'phone'            => '无效的手机号',
        'uid'              => '请求来源有误[无法识别用户]',
        'deviceId'         => '请求来源有误[未知的平台]',
        'refreshToken'     => '请求来源有误[无效的请求]',
    ];

    // 验证场景
    protected $scene = [
        // 常规登录
        'login'      => ['passport', 'password', 'deviceId'],
        // 手机号登录
        'phoneLogin' => ['phone', 'code', 'deviceId'],
        // 手机号验证
        'phone'      => ['phone'],
        // 刷新token
        'refresh'    => ['uid', 'deviceId', 'refreshToken'],
    ];
}
